package com.insigma.business.common.controller;

import com.insigma.business.common.service.DfsService;
import com.insigma.business.common.utils.MinIoUtil;
import com.insigma.framework.ResponseMessage;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/common/dfs")
public class DfsController {
    @Resource
    private DfsService dfsService;

    @PostMapping("/upload")
    public ResponseMessage upload(@RequestParam("file")MultipartFile file,@RequestParam("modelName")String modelName) {
        try {
            return ResponseMessage.ok(dfsService.upload(file,"qrcode",modelName));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @PostMapping("/uploadRetainChName")
    public ResponseMessage uploadRetainChName(@RequestParam("file")MultipartFile file,@RequestParam("modelName")String modelName) {
        try {
            return ResponseMessage.ok(dfsService.uploadRetainChName(file,"qrcode",modelName));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @PostMapping("/preViewFile")
    public ResponseMessage preViewFile(@RequestParam("filePath")String filePath,@RequestParam("endpoint")String endpoint) {
        try {
            return ResponseMessage.ok(dfsService.preViewFile(filePath,endpoint));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
